define(function (require) {
    var $ = require("./zepto");
    var global = require("./global");
    var page = require("./page");
    var map = require("./map");
    var form = require("./form");
    var r = {
        mapCreate: function () {
            if (!(0 >= ".j-map".length)) {
                var t = $(".j-map"), i = {fnOpen: global._scrollStop, fnClose: map.mapSave};
                map.mapAddEventHandler(t, "click", map.mapShow, i);
            }
        },
        Txt_init: function (t) {
            0 >= t.find(".j-txt").length || 0 >= t.find(".j-txt").find(".j-detail p").length || t.find(".j-txt").each(function () {
                var t = $(this).find(".j-detail"), i = $(this).find(".j-title"), a = i.find(".txt-arrow"), o = t.find("p"), r = parseInt(i.height()), s = parseInt(o.height()), l = s + r;
                0 >= o.length || ($(this).parents(".m-page").hasClass("m-smallTxt") && (0 == $(this).parents(".smallTxt-bd").index() ? t.css("top", r) : t.css("bottom", r)), t.attr("data-height", s), $(this).attr("data-height-init", r), $(this).attr("data-height-extand", l), o[0].style[global._prefixStyle("transform")] = "translate(0,-" + s + "px)", $(this.parentNode).hasClass("z-left") && (o[0].style[global._prefixStyle("transform")] = "translate(0," + s + "px)"), t.css("height", "0"), a.removeClass("z-toggle"), $(this).css("height", r))
            })
        },
        bigTxt_extand: function () {
            $("body").on("click", ".j-title", function () {
                if (!(0 >= $(".j-detail").length)) {
                    var t = $(this.parentNode).find(".j-detail");
                    $(".j-detail").removeClass("action"), t.addClass("action"), $(this).hasClass("smallTxt-arrow") && ($(".smallTxt-bd").removeClass("action"), t.parent().addClass("action")), t.hasClass("z-show") ? (t.removeClass("z-show"), t.css("height", 0), $(this.parentNode).css("height", parseInt($(this.parentNode).attr("data-height-init")))) : (t.addClass("z-show"), t.css("height", parseInt(t.attr("data-height"))), $(this.parentNode).css("height", parseInt($(this.parentNode).attr("data-height-extand")))), $(".j-detail").not(".action").removeClass("z-show"), $(".txt-arrow").removeClass("z-toggle"), t.hasClass("z-show") ? $(this).find(".txt-arrow").addClass("z-toggle") : $(this).find(".txt-arrow").removeClass("z-toggle")
                }
            })
        },
        Txt_back: function () {
            $("body").on("click", ".m-page", function (t) {
                t.stopPropagation();
                var n = $(t.target), i = n.parents(".m-page"), a = 0 == n.parents(".j-txtWrap").length ? n : n.parents(".j-txtWrap");
                if (!(0 >= i.find(".j-txt").find(".j-detail p").length || 0 >= i.find(".j-txt").length || n.parents(".j-txt").length >= 1 || n.hasClass("bigTxt-btn") || n.parents(".bigTxt-btn").length >= 1)) {
                    var o = a.find(".j-detail");
                    $(".j-detail").removeClass("action"), o.addClass("action"), $(".j-detail").not(".action").removeClass("z-show"), a.each(function () {
                        var t = $(this).find(".j-detail"), n = $(this).find(".txt-arrow"), i = $(this).find(".j-txt");
                        t.hasClass("z-show") ? (t.removeClass("z-show"), t.css("height", 0), i.css("height", parseInt(i.attr("data-height-init")))) : (t.addClass("z-show"), t.css("height", parseInt(t.attr("data-height"))), i.css("height", parseInt(i.attr("data-height-extand")))), t.hasClass("z-show") ? n.addClass("z-toggle") : n.removeClass("z-toggle")
                    })
                }
            })
        },
        input_form: function () {
            $("body").on("click", ".book-bd .bd-form .btn", function () {
                var t = $(this).attr("data-submit");
                if ("true" != t) {
                    var a = $(window).height();
                    $(document.body).css("height", a), page.page_stop(), global._scrollStart(), page._page.eq(page._pageNow).css("z-index", 15), $(".book-bg").removeClass("f-hide"), $(".book-form").removeClass("f-hide"), setTimeout(function () {
                        $(".book-form").addClass("z-show"), $(".book-bg").addClass("z-show")
                    }, 50), $(".book-bg").off("click"), $(".book-bg").on("click", function (t) {
                        t.stopPropagation();
                        var a = $(t.target);
                        a.parents(".book-form").length >= 1 && !a.hasClass("j-close-img") && 0 >= a.parents(".j-close").length || ($(".book-form").removeClass("z-show"), $(".book-bg").removeClass("z-show"), setTimeout(function () {
                            $(document.body).css("height", "100%"), page.page_start(), global._scrollStop(), page._page.eq(page._pageNow).css("z-index", 9), $(".book-bg").addClass("f-hide"), $(".book-form").addClass("f-hide")
                        }, 500))
                    })
                }
            })
        },
        sex_select: function () {
            var t = $("#j-signUp").find(".sex p"), n = $("#j-signUp").find(".sex strong"), i = $("#j-signUp").find(".sex input");
            t.on("click", function () {
                var t = $(this).find("strong");
                n.removeClass("open"), t.addClass("open");
                var a = $(this).attr("data-sex");
                i.val(a)
            })
        }, lightapp_intro_show: function () {
            $(".market-notice").removeClass("f-hide"), setTimeout(function () {
                $(".market-notice").addClass("show")
            }, 100)
        }, lightapp_intro_hide: function (t) {
            return t ? ($(".market-notice").addClass("f-hide").removeClass("show"), void 0) : ($(".market-notice").removeClass("show"), setTimeout(function () {
                $(".market-notice").addClass("f-hide")
            }, 500), void 0)
        }, lightapp_intro: function () {
            $(".market-notice").off("click"), $(".market-notice").on("click", function () {
                $(".market-page").removeClass("f-hide"), setTimeout(function () {
                    $(".market-page").addClass("show"), setTimeout(function () {
                        $(".market-img").addClass("show")
                    }, 100), r.lightapp_intro_hide()
                }, 100), page.page_stop(), global._scrollStop()
            }), $(".market-page").off("click"), $(".market-page").on("click", function (t) {
                $(t.target).hasClass("market-page") && ($(".market-img").removeClass("show"), setTimeout(function () {
                    $(".market-page").removeClass("show"), setTimeout(function () {
                        $(".market-page").addClass("f-hide")
                    }, 200)
                }, 500), r.lightapp_intro_show(), page.page_start(), global._scrollStart())
            })
        },
        ajaxTongji: function (t) {
            return;
            var n = location.search.substr(location.search.indexOf("channel=") + 8);
            n = n.match(/^\d+/), (!n || isNaN(n) || 0 > n) && (n = 1);
            var i = $("#activity_id").val(), a = "/analyseplugin/plugin?activity_id=" + i + "&plugtype=" + t;
            $.get(a, {}, function () {
            })
        }, wxShare: function () {
            $("body").on("click", ".bigTxt-btn-wx", function () {
                var t = $(this).parent().find(".bigTxt-weixin");
                t.addClass("z-show"), page.page_stop(), t.on("click", function () {
                    $(this).removeClass("z-show"), page.page_start(), $(this).off("click")
                })
            })
        }, toggleVideo: function () {
            $(".j-video").find(".img").on("click", function () {
                var t = $(this).next()[0];
                0 >= t.length || t.paused && ($(t).removeClass("f-hide"), t.play(), $(this).hide())
            })
        }, signUp_submit: function () {
            $("#j-signUp-submit").on("click", function (t) {
                t.preventDefault();
                var n = $(this).parents("#j-signUp"), i = form.signUpCheck_input(n, $(".u-note"));
                i && form.signUpCheck_submit(n, $(".u-note"))
            })
        }, loadingPageShow: function () {
            $(".u-pageLoading").show()
        }, loadingPageHide: function () {
            $(".u-pageLoading").hide()
        }};
    return $(function () {
        r.bigTxt_extand(), r.Txt_back(), r.input_form(), r.sex_select(), r.lightapp_intro(), r.wxShare(), r.mapCreate(), r.toggleVideo(), r.signUp_submit(), r.Txt_init(page._page.eq(page._pageNow))
    }), r
});
